package formBean;

import java.util.ArrayList;
import java.util.List;

import org.mybeans.form.FormBean;

import util.Util;

public class CreateFundForm extends FormBean{
	private String fundname;
	private String ticker;
	
	public String getFundname() {
		return fundname;
	}
	
	public void setFundname(String fundname) {
		this.fundname = trimAndConvert(fundname,"<>\"");
	}
	
	public String getTicker() {
		return ticker;
	}

	public void setTicker(String ticker) {
		this.ticker = trimAndConvert(ticker, "<>\"");
	}
	
	public List<String> getValidationErrors() {
		List<String> errors = new ArrayList<String>();
		
		if (fundname == null || fundname.length() == 0) {
			errors.add("Fund Name is required");
		}
		
		if (ticker == null || ticker.length() == 0) {
			errors.add("Ticker is required");
		}
		
		if (errors.size() > 0) return errors;
		
		if (fundname.length() > 15) {
			errors.add("Fund name should not be longer than 15 characters.");
		}
		
		if (ticker.length() > 5) {
			errors.add("Ticker should not be longer than 5 characters.");
		}		
		
		if (!Util.isValidUsername(this.fundname)) {
			errors.add("Fund name is not a valid one.");
		}
		
		if (!Util.isValidTicker(this.ticker)) {
			errors.add("Ticker is not a valid one. It should only contain letters.");
		}
		
		if (fundname.matches(".*[<>\"].*")) errors.add("Fund name may not contain angle brackets or quotes");
		if (ticker.matches(".*[<>\"].*")) errors.add("The ticker may not contain angle brackets or quotes");
		
		return errors;
	}
}
